/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package androidgetdata;

import java.io.IOException;
import java.util.List;

/**
 *
 * @author asus
 */
public class AndroidDataFactory {

    public static final String VIEC_LAM = "ViecLam";
    public static final String KHOA_HOC = "KhoaHoc";
    public static final String TIN_MOI = "TinMoi";

    /**
     *
     * @param strData such as: ViecLam, KhoaHoc
     * @return
     */
    public static List<NewsPreview> getListNewsPreview(String strData) throws IOException {
        String dataUrl = "";
        switch (strData) {
            case TIN_MOI:
                return AndroidGetData.getListNewNewsPreview(ConstantCompare.URL_TIN_MOI);
            case VIEC_LAM:
                dataUrl = ConstantCompare.URL_VIEC_LAM;
                break;
            case KHOA_HOC:
                dataUrl = ConstantCompare.URL_KHOA_HOC;
                break;
        }
        // if dataUrl is null, return null value
        // else return list of news
        if (dataUrl.equals("")) {
            return null;
        } else {
            return AndroidGetData.getListNewsPreview(dataUrl,true);
        }
    }
    
    /**
     * 
     * @param strData
     * @param pageIndex
     * @return
     * @throws IOException 
     */
    public static List<NewsPreview> getListNewsPreview(String strData, int pageIndex) throws IOException {
        String dataUrl = "";
        switch (strData) {
            case VIEC_LAM: 
                dataUrl = ConstantCompare.URL_VIEC_LAM + ConstantCompare.URL_PAGE_SUB + pageIndex;
                break;
            case KHOA_HOC: 
                dataUrl = ConstantCompare.URL_KHOA_HOC + ConstantCompare.URL_PAGE_SUB + pageIndex;
                break;
        }
        
        // if dataUrl is null, return null value
        // else return list of news
        if (dataUrl.equals("")) {
            return null;
        } else {
            return AndroidGetData.getListNewsPreview(dataUrl,false);
        }
    }
}
